package codeMonkeyClock;

//import processing.core.*;

/**
 *  Hand - class to draw hands on the face of the clock
 *  
 *  Copyright (C) 2013  Samantha Lycett
 *  
 *  This file is part of CodeMonkeyClock.
 *
 *  CodeMonkeyClock is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *
 *  CodeMonkeyClock is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CodeMonkeyClock.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 
 * @author sam
 * @created 13 June 2013
 * @version 18 June 2013
 */
public class Hand {

	float fractionLength = (float)0.75;		// length of hand expressed as a fraction
	float fractionAngle  = 0;				// fraction of angle between 0 - 1 (0 = 12)
	float fractionWidth  = (float)0.05;		// width of hand expressed as a fraction
	
	double angle;							// angle in radians from "North"
	
	CodeMonkeyClock myParent;				// this is the main clock face and is a PApplet
	
	public Hand(CodeMonkeyClock p, float fractionLength, float fractionAngle, float fractionWidth) {
		myParent 			= p;
		this.fractionLength = fractionLength;
		this.fractionAngle  = fractionAngle;
		this.fractionWidth  = fractionWidth;
		
		drawShape();
	}
	
	
	/**
	 * draws a quadrilateral shape for a clock hand on the CodeMonkeyClock parent, which is a PApplet
	 * or if fractionWidth = 0, then just draws the line
	 */
	private void drawShape() {
		
		angle 			= (double)fractionAngle*2*Math.PI - (Math.PI/2);
		
		float r  		= myParent.minD*fractionLength/2;			// radius
		
		float x1 		= myParent.xc;								// centre point
		float y1 		= myParent.yc;
		
		float x3 		= myParent.xc + r*(float)Math.cos(angle);	// outer point of hand
		float y3 		= myParent.yc + r*(float)Math.sin(angle);
		
		if (fractionWidth > 0) {
			float r2		= myParent.minD*fractionWidth/4;				// radius of cross of hand
		
			float midX		= myParent.xc + (r/2)*(float)Math.cos(angle); 	// centre point of cross
			float midY		= myParent.yc + (r/2)*(float)Math.sin(angle);
		
			float x2		= midX + r2*(float)Math.cos(angle-Math.PI/2);
			float y2		= midY + r2*(float)Math.sin(angle-Math.PI/2);
		
			float x4		= midX + r2*(float)Math.cos(angle+Math.PI/2);
			float y4		= midY + r2*(float)Math.sin(angle+Math.PI/2);
		
			myParent.fill(360*fractionAngle,100,75);
			myParent.quad(x1, y1, x2, y2, x3, y3, x4, y4);
		}
		
		myParent.stroke(360*fractionAngle,100,50);
		myParent.line(x1, y1, x3, y3);
	}
	
	
}
